package com.tedu.swaggerdemo.controller;

import com.tedu.swaggerdemo.pojo.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/user")
@Api(value = "UserController"
        , description = "用户接口"

)
public class UserController {

    @RequestMapping("/login")
    @ApiOperation(value = "登录", notes = "接收username,password，进行登录")
    public JsonResult login(String username, String password) {

        JsonResult jsonResult = new JsonResult(0, "success", null);
        return jsonResult;
    }

    @RequestMapping("/register")
    @ApiOperation(notes = "接收username,password,id不用输入", value = "注册", httpMethod = "POST")
    @ApiImplicitParam(name = "id",value = "不用输入")
    public JsonResult register(User user) {
        if ("admin".equals(user.getUsername()) && "admin".equals(user.getPassword())) {
            JsonResult jsonResult = new JsonResult(500, "admin已经存在", null);
            return jsonResult;
        }

        user.setId(90);
        JsonResult jsonResult = new JsonResult(0, "success", user);
        return jsonResult;
    }

}
